{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "from stocker import Stocker"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "AMZN Stocker Initialized. Data covers 1997-05-16 00:00:00 to 2018-03-27 00:00:00.\n"
     ]
    }
   ],
   "source": [
    "amazon = Stocker('AMZN')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Date</th>\n",
       "      <th>Open</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Close</th>\n",
       "      <th>Volume</th>\n",
       "      <th>Ex-Dividend</th>\n",
       "      <th>Split Ratio</th>\n",
       "      <th>Adj. Open</th>\n",
       "      <th>Adj. High</th>\n",
       "      <th>Adj. Low</th>\n",
       "      <th>Adj. Close</th>\n",
       "      <th>Adj. Volume</th>\n",
       "      <th>ds</th>\n",
       "      <th>y</th>\n",
       "      <th>Daily Change</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1997-05-16</td>\n",
       "      <td>22.38</td>\n",
       "      <td>23.75</td>\n",
       "      <td>20.50</td>\n",
       "      <td>20.75</td>\n",
       "      <td>1225000.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.865000</td>\n",
       "      <td>1.979167</td>\n",
       "      <td>1.708333</td>\n",
       "      <td>1.729167</td>\n",
       "      <td>14700000.0</td>\n",
       "      <td>1997-05-16</td>\n",
       "      <td>1.729167</td>\n",
       "      <td>-0.135833</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1997-05-19</td>\n",
       "      <td>20.50</td>\n",
       "      <td>21.25</td>\n",
       "      <td>19.50</td>\n",
       "      <td>20.50</td>\n",
       "      <td>508900.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.708333</td>\n",
       "      <td>1.770833</td>\n",
       "      <td>1.625000</td>\n",
       "      <td>1.708333</td>\n",
       "      <td>6106800.0</td>\n",
       "      <td>1997-05-19</td>\n",
       "      <td>1.708333</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1997-05-20</td>\n",
       "      <td>20.75</td>\n",
       "      <td>21.00</td>\n",
       "      <td>19.63</td>\n",
       "      <td>19.63</td>\n",
       "      <td>455600.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.729167</td>\n",
       "      <td>1.750000</td>\n",
       "      <td>1.635833</td>\n",
       "      <td>1.635833</td>\n",
       "      <td>5467200.0</td>\n",
       "      <td>1997-05-20</td>\n",
       "      <td>1.635833</td>\n",
       "      <td>-0.093333</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1997-05-21</td>\n",
       "      <td>19.25</td>\n",
       "      <td>19.75</td>\n",
       "      <td>16.50</td>\n",
       "      <td>17.13</td>\n",
       "      <td>1571100.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.604167</td>\n",
       "      <td>1.645833</td>\n",
       "      <td>1.375000</td>\n",
       "      <td>1.427500</td>\n",
       "      <td>18853200.0</td>\n",
       "      <td>1997-05-21</td>\n",
       "      <td>1.427500</td>\n",
       "      <td>-0.176667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1997-05-22</td>\n",
       "      <td>17.25</td>\n",
       "      <td>17.38</td>\n",
       "      <td>15.75</td>\n",
       "      <td>16.75</td>\n",
       "      <td>981400.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.437500</td>\n",
       "      <td>1.448333</td>\n",
       "      <td>1.312500</td>\n",
       "      <td>1.395833</td>\n",
       "      <td>11776800.0</td>\n",
       "      <td>1997-05-22</td>\n",
       "      <td>1.395833</td>\n",
       "      <td>-0.041667</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        Date   Open   High    Low  Close     Volume  Ex-Dividend  Split Ratio  \\\n",
       "0 1997-05-16  22.38  23.75  20.50  20.75  1225000.0          0.0          1.0   \n",
       "1 1997-05-19  20.50  21.25  19.50  20.50   508900.0          0.0          1.0   \n",
       "2 1997-05-20  20.75  21.00  19.63  19.63   455600.0          0.0          1.0   \n",
       "3 1997-05-21  19.25  19.75  16.50  17.13  1571100.0          0.0          1.0   \n",
       "4 1997-05-22  17.25  17.38  15.75  16.75   981400.0          0.0          1.0   \n",
       "\n",
       "   Adj. Open  Adj. High  Adj. Low  Adj. Close  Adj. Volume         ds  \\\n",
       "0   1.865000   1.979167  1.708333    1.729167   14700000.0 1997-05-16   \n",
       "1   1.708333   1.770833  1.625000    1.708333    6106800.0 1997-05-19   \n",
       "2   1.729167   1.750000  1.635833    1.635833    5467200.0 1997-05-20   \n",
       "3   1.604167   1.645833  1.375000    1.427500   18853200.0 1997-05-21   \n",
       "4   1.437500   1.448333  1.312500    1.395833   11776800.0 1997-05-22   \n",
       "\n",
       "          y  Daily Change  \n",
       "0  1.729167     -0.135833  \n",
       "1  1.708333      0.000000  \n",
       "2  1.635833     -0.093333  \n",
       "3  1.427500     -0.176667  \n",
       "4  1.395833     -0.041667  "
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "stock_history = amazon.stock\n",
    "stock_history.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "f = open('amzn1.txt','w')\n",
    "f.write(str(stock_history.head()))\n",
    "f.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(['Adj. Close'],\n",
       " 1598.39,\n",
       " Timestamp('2018-03-12 00:00:00'),\n",
       " 1.3958333333333333,\n",
       " Timestamp('1997-05-22 00:00:00'),\n",
       " 1497.05,\n",
       " Timestamp('2018-03-27 00:00:00'))"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "amazon.plot_stock()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [],
   "source": [
    "f = open('amzn2.txt','w')\n",
    "f.write(str(amazon.plot_stock()))\n",
    "f.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(['Daily Change'],\n",
       " 81.37999999999988,\n",
       " Timestamp('2018-02-06 00:00:00'),\n",
       " -79.20000000000005,\n",
       " Timestamp('2018-02-08 00:00:00'),\n",
       " -75.35000000000014,\n",
       " Timestamp('2018-03-27 00:00:00'))"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "amazon.plot_stock(stats=['Daily Change'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [],
   "source": [
    "f = open('amzn3.txt','w')\n",
    "f.write(str(amazon.plot_stock(stats=['Daily Change'])))\n",
    "f.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Downloads\\Anaconda\\lib\\site-packages\\pystan\\misc.py:399: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
      "  elif np.issubdtype(np.asarray(v).dtype, float):\n"
     ]
    }
   ],
   "source": [
    "model, model_data = amazon.create_prophet_model(days=90)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Downloads\\Anaconda\\lib\\site-packages\\pystan\\misc.py:399: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
      "  elif np.issubdtype(np.asarray(v).dtype, float):\n"
     ]
    }
   ],
   "source": [
    "f = open('amzn4.txt','w')\n",
    "f.write(str(amazon.create_prophet_model(days=90)))\n",
    "f.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Downloads\\Anaconda\\lib\\site-packages\\pystan\\misc.py:399: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
      "  elif np.issubdtype(np.asarray(v).dtype, float):\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "('Prediction Range',\n",
       " Timestamp('2017-03-27 00:00:00'),\n",
       " Timestamp('2018-03-27 00:00:00'),\n",
       " 'Predicted price',\n",
       " Timestamp('2018-03-24 00:00:00'),\n",
       " 1054.937535885287,\n",
       " 'Actual price',\n",
       " Timestamp('2018-03-23 00:00:00'),\n",
       " 1495.56,\n",
       " 'Average Absolute Error on Training Data',\n",
       " 16.863070266740877,\n",
       " 'Average Absolute Error on Testing  Data',\n",
       " 138.46083299702494,\n",
       " 'the model predicted an increase, the price increased',\n",
       " 56.41025641025641,\n",
       " 'the model predicted a  decrease, the price decreased',\n",
       " 40.21739130434783,\n",
       " 'actual value was within the',\n",
       " 80,\n",
       " 'confidence interval',\n",
       " 59.43775100401606)"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "amazon.evaluate_prediction()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Downloads\\Anaconda\\lib\\site-packages\\pystan\\misc.py:399: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
      "  elif np.issubdtype(np.asarray(v).dtype, float):\n"
     ]
    }
   ],
   "source": [
    "f = open('amzn5.txt','w')\n",
    "f.write(str(amazon.evaluate_prediction()))\n",
    "f.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "amazon.changepoint_prior_scale = 0.5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Downloads\\Anaconda\\lib\\site-packages\\pystan\\misc.py:399: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
      "  elif np.issubdtype(np.asarray(v).dtype, float):\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "('Prediction Range',\n",
       " Timestamp('2017-03-27 00:00:00'),\n",
       " Timestamp('2018-03-27 00:00:00'),\n",
       " 'Predicted price',\n",
       " Timestamp('2018-03-24 00:00:00'),\n",
       " 1000.4491502174986,\n",
       " 'Actual price',\n",
       " Timestamp('2018-03-23 00:00:00'),\n",
       " 1495.56,\n",
       " 'Average Absolute Error on Training Data',\n",
       " 10.862968608001228,\n",
       " 'Average Absolute Error on Testing  Data',\n",
       " 177.41167877880943,\n",
       " 'the model predicted an increase, the price increased',\n",
       " 59.73154362416108,\n",
       " 'the model predicted a  decrease, the price decreased',\n",
       " 45.45454545454545,\n",
       " 'actual value was within the',\n",
       " 80,\n",
       " 'confidence interval',\n",
       " 86.34538152610442)"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "amazon.evaluate_prediction()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Downloads\\Anaconda\\lib\\site-packages\\pystan\\misc.py:399: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
      "  elif np.issubdtype(np.asarray(v).dtype, float):\n"
     ]
    }
   ],
   "source": [
    "f = open('amzn6.txt','w')\n",
    "f.write(str(amazon.evaluate_prediction()))\n",
    "f.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "amazon.weekly_seasonality=True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Downloads\\Anaconda\\lib\\site-packages\\pystan\\misc.py:399: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
      "  elif np.issubdtype(np.asarray(v).dtype, float):\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "('Prediction Range',\n",
       " Timestamp('2017-03-27 00:00:00'),\n",
       " Timestamp('2018-03-27 00:00:00'),\n",
       " 'Predicted price',\n",
       " Timestamp('2018-03-24 00:00:00'),\n",
       " 970.3728466720872,\n",
       " 'Actual price',\n",
       " Timestamp('2018-03-23 00:00:00'),\n",
       " 1495.56,\n",
       " 'Average Absolute Error on Training Data',\n",
       " 10.811953374853106,\n",
       " 'Average Absolute Error on Testing  Data',\n",
       " 182.25442598782627,\n",
       " 'the model predicted an increase, the price increased',\n",
       " 61.18421052631579,\n",
       " 'the model predicted a  decrease, the price decreased',\n",
       " 47.91666666666667,\n",
       " 'actual value was within the',\n",
       " 80,\n",
       " 'confidence interval',\n",
       " 82.32931726907631)"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "amazon.evaluate_prediction()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Downloads\\Anaconda\\lib\\site-packages\\pystan\\misc.py:399: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
      "  elif np.issubdtype(np.asarray(v).dtype, float):\n"
     ]
    }
   ],
   "source": [
    "f = open('amzn7.txt','w')\n",
    "f.write(str(amazon.evaluate_prediction()))\n",
    "f.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "amazon.changepoint_prior_scale=0.5\n",
    "amazon.weekly_seasonality=True"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Downloads\\Anaconda\\lib\\site-packages\\pystan\\misc.py:399: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
      "  elif np.issubdtype(np.asarray(v).dtype, float):\n",
      "C:\\Users\\Lancer\\股票项目\\AMZN\\stocker.py:626: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n",
      "  test_pred_increase['pred_profit'] = prediction_profit\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "('Date',\n",
       " 'AMZN',\n",
       " Timestamp('2017-03-27 00:00:00'),\n",
       " Timestamp('2018-03-27 00:00:00'),\n",
       " 1000,\n",
       " 'the model predicted an increase, the price increased',\n",
       " 61.18421052631579,\n",
       " 'the model predicted a  decrease, the price decreased',\n",
       " 47.91666666666667,\n",
       " 'The total profit using the Prophet model',\n",
       " 571679.9999999998,\n",
       " 'The Buy and Hold strategy profit',\n",
       " 648739.9999999999)"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "amazon.evaluate_prediction(nshares=1000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Downloads\\Anaconda\\lib\\site-packages\\pystan\\misc.py:399: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
      "  elif np.issubdtype(np.asarray(v).dtype, float):\n",
      "C:\\Users\\Lancer\\股票项目\\AMZN\\stocker.py:626: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n",
      "  test_pred_increase['pred_profit'] = prediction_profit\n"
     ]
    }
   ],
   "source": [
    "f = open('amzn8.txt','w')\n",
    "f.write(str(amazon.evaluate_prediction(nshares=1000)))\n",
    "f.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Downloads\\Anaconda\\lib\\site-packages\\pystan\\misc.py:399: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
      "  elif np.issubdtype(np.asarray(v).dtype, float):\n",
      "C:\\Users\\Lancer\\股票项目\\AMZN\\stocker.py:626: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n",
      "  test_pred_increase['pred_profit'] = prediction_profit\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "('Date',\n",
       " 'AMZN',\n",
       " Timestamp('2008-01-03 00:00:00'),\n",
       " Timestamp('2009-01-05 00:00:00'),\n",
       " 1000,\n",
       " 'the model predicted an increase, the price increased',\n",
       " 42.69005847953216,\n",
       " 'the model predicted a  decrease, the price decreased',\n",
       " 53.75,\n",
       " 'The total profit using the Prophet model',\n",
       " -42230.0,\n",
       " 'The Buy and Hold strategy profit',\n",
       " -43929.99999999999)"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "amazon.evaluate_prediction(start_date = '2008-01-03', end_date = '2009-01-05', nshares=1000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Downloads\\Anaconda\\lib\\site-packages\\pystan\\misc.py:399: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
      "  elif np.issubdtype(np.asarray(v).dtype, float):\n",
      "C:\\Users\\Lancer\\股票项目\\AMZN\\stocker.py:626: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame.\n",
      "Try using .loc[row_indexer,col_indexer] = value instead\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n",
      "  test_pred_increase['pred_profit'] = prediction_profit\n"
     ]
    }
   ],
   "source": [
    "f = open('amzn9.txt','w')\n",
    "f.write(str(amazon.evaluate_prediction(start_date = '2008-01-03', end_date = '2009-01-05',nshares=1000)))\n",
    "f.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Downloads\\Anaconda\\lib\\site-packages\\pystan\\misc.py:399: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
      "  elif np.issubdtype(np.asarray(v).dtype, float):\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(         Date     estimate     change        upper        lower\n",
       " 1  2018-03-28  1577.065947   2.974182  1598.584786  1554.959769\n",
       " 2  2018-03-29  1579.669256   2.603309  1601.778130  1558.746497\n",
       " 3  2018-03-30  1586.396412   6.727156  1610.205533  1565.752151\n",
       " 5  2018-04-01  1626.513875  40.117463  1648.533026  1606.579359\n",
       " 8  2018-04-04  1602.594174   1.152385  1623.814475  1580.190453\n",
       " 9  2018-04-05  1605.235273   2.641100  1625.660954  1583.414106\n",
       " 10 2018-04-06  1612.338805   7.103532  1634.788626  1590.454491,\n",
       "         Date     estimate     change        upper        lower\n",
       " 6 2018-04-02  1601.561128 -24.952748  1624.224205  1579.117443\n",
       " 7 2018-04-03  1601.441789  -0.119339  1622.109638  1580.181431)"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "amazon.predict_future(days=10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Downloads\\Anaconda\\lib\\site-packages\\pystan\\misc.py:399: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
      "  elif np.issubdtype(np.asarray(v).dtype, float):\n"
     ]
    }
   ],
   "source": [
    "f = open('amzn10.txt','w')\n",
    "f.write(str(amazon.predict_future(days=10)))\n",
    "f.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Downloads\\Anaconda\\lib\\site-packages\\pystan\\misc.py:399: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
      "  elif np.issubdtype(np.asarray(v).dtype, float):\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(         Date     estimate     change        upper        lower\n",
       " 1  2018-03-28  1577.065947   2.974182  1600.050950  1555.439976\n",
       " 2  2018-03-29  1579.669256   2.603309  1600.820864  1557.294424\n",
       " 3  2018-03-30  1586.396412   6.727156  1609.246939  1566.182239\n",
       " 5  2018-04-01  1626.513875  40.117463  1647.375160  1605.535927\n",
       " 8  2018-04-04  1602.594174   1.152385  1624.086521  1580.818126\n",
       " 9  2018-04-05  1605.235273   2.641100  1628.211137  1583.297821\n",
       " 10 2018-04-06  1612.338805   7.103532  1634.937827  1589.635504\n",
       " 12 2018-04-08  1650.276017  37.937212  1673.582124  1626.685638\n",
       " 14 2018-04-10  1626.518012   1.672535  1651.872773  1600.843295\n",
       " 15 2018-04-11  1630.966435   4.448423  1653.890025  1606.183152\n",
       " 16 2018-04-12  1636.043334   5.076899  1659.891663  1611.130008\n",
       " 17 2018-04-13  1642.853409   6.810075  1666.137949  1618.548761\n",
       " 19 2018-04-15  1675.316733  32.463324  1699.973878  1650.058540\n",
       " 21 2018-04-17  1651.342573   2.420527  1679.955075  1621.195562\n",
       " 22 2018-04-18  1656.229197   4.886624  1683.463760  1626.875569\n",
       " 23 2018-04-19  1659.631398   3.402201  1687.204668  1628.990099\n",
       " 24 2018-04-20  1663.017303   3.385905  1691.309299  1633.268162\n",
       " 26 2018-04-22  1692.806289  29.788986  1721.823778  1660.968138\n",
       " 28 2018-04-24  1675.505346   6.073694  1706.405145  1641.433442\n",
       " 29 2018-04-25  1682.234509   6.729163  1717.730676  1648.059430\n",
       " 30 2018-04-26  1685.326471   3.091962  1719.590240  1647.412436\n",
       " 31 2018-04-27  1688.259134   2.932663  1725.297129  1653.592384\n",
       " 33 2018-04-29  1723.991234  35.732100  1763.203466  1684.248849\n",
       " 35 2018-05-01  1712.803211   7.780743  1752.742336  1674.675258\n",
       " 36 2018-05-02  1717.511870   4.708658  1758.579457  1672.076829\n",
       " 40 2018-05-06  1750.443006  34.449056  1802.730663  1696.472159\n",
       " 42 2018-05-08  1737.411015   6.318092  1791.269001  1674.586052\n",
       " 43 2018-05-09  1740.772508   3.361493  1796.999796  1683.373401\n",
       " 45 2018-05-11  1742.539943   2.240548  1802.170527  1675.127056\n",
       " 47 2018-05-13  1781.345436  38.805493  1849.416382  1710.705046\n",
       " 49 2018-05-15  1763.484049   3.194325  1834.792822  1685.327954\n",
       " 50 2018-05-16  1764.702058   1.218009  1845.410166  1684.937335\n",
       " 52 2018-05-18  1766.973857   2.869264  1848.011258  1681.555651\n",
       " 54 2018-05-20  1801.732661  34.758804  1898.780815  1710.137878\n",
       " 56 2018-05-22  1777.743308   1.058346  1870.370629  1684.862083\n",
       " 57 2018-05-23  1779.987227   2.243919  1875.247093  1684.403430\n",
       " 58 2018-05-24  1782.294413   2.307186  1882.049036  1680.913239\n",
       " 59 2018-05-25  1787.261805   4.967392  1894.063413  1674.999079\n",
       " 61 2018-05-27  1820.056613  32.794808  1927.066086  1711.593710\n",
       " 63 2018-05-29  1797.620554   3.167089  1916.406907  1686.520392\n",
       " 64 2018-05-30  1803.549180   5.928627  1924.752256  1681.311940\n",
       " 65 2018-05-31  1808.214363   4.665183  1934.219092  1682.945937\n",
       " 66 2018-06-01  1812.012290   3.797927  1938.457847  1681.622877\n",
       " 68 2018-06-03  1835.544806  23.532516  1967.704487  1702.025794\n",
       " 70 2018-06-05  1808.729930   2.004389  1958.012728  1671.263322\n",
       " 71 2018-06-06  1814.025879   5.295949  1967.307287  1670.113921\n",
       " 72 2018-06-07  1817.157241   3.131363  1969.256051  1671.055459\n",
       " 73 2018-06-08  1818.827714   1.670473  1976.584693  1667.461677\n",
       " 75 2018-06-10  1842.802129  23.974415  2002.098870  1687.758755\n",
       " 77 2018-06-12  1821.283809   4.265229  1988.442838  1655.324353\n",
       " 78 2018-06-13  1826.172289   4.888480  1999.025291  1654.736569\n",
       " 79 2018-06-14  1826.560001   0.387712  1995.277043  1647.833448\n",
       " 82 2018-06-17  1848.970821  23.608512  2044.931028  1669.405830\n",
       " 84 2018-06-19  1825.944385   2.435196  2017.760981  1637.400397\n",
       " 85 2018-06-20  1827.211513   1.267128  2026.432140  1635.571234\n",
       " 89 2018-06-24  1852.909001  29.689181  2067.831481  1646.511279\n",
       " 91 2018-06-26  1830.868037   1.867297  2049.674403  1611.289409\n",
       " 92 2018-06-27  1831.478169   0.610132  2060.305726  1607.628706\n",
       " 94 2018-06-29  1833.276124   2.821208  2065.716503  1602.666524\n",
       " 96 2018-07-01  1869.409104  36.132979  2111.970255  1628.357631,\n",
       "           Date     estimate     change        upper        lower\n",
       " 6   2018-04-02  1601.561128 -24.952748  1623.091756  1579.772196\n",
       " 7   2018-04-03  1601.441789  -0.119339  1624.834792  1578.619660\n",
       " 13  2018-04-09  1624.845477 -25.430540  1648.233908  1601.439089\n",
       " 20  2018-04-16  1648.922046 -26.394687  1677.822129  1622.558224\n",
       " 27  2018-04-23  1669.431651 -23.374638  1700.958906  1638.409732\n",
       " 34  2018-04-30  1705.022468 -18.968766  1741.122640  1662.812767\n",
       " 37  2018-05-03  1716.500805  -1.011065  1761.006367  1672.815092\n",
       " 38  2018-05-04  1715.993950  -0.506854  1766.206151  1663.559377\n",
       " 41  2018-05-07  1731.092923 -19.350083  1790.033318  1675.364462\n",
       " 44  2018-05-10  1740.299395  -0.473113  1800.716991  1673.456667\n",
       " 48  2018-05-14  1760.289724 -21.055712  1829.501999  1688.358331\n",
       " 51  2018-05-17  1764.104593  -0.597465  1844.207113  1682.855678\n",
       " 55  2018-05-21  1776.684962 -25.047699  1868.290653  1687.925630\n",
       " 62  2018-05-28  1794.453465 -25.603148  1912.118019  1680.474336\n",
       " 69  2018-06-04  1806.725541 -28.819266  1951.788779  1679.552640\n",
       " 76  2018-06-11  1817.018580 -25.783549  1984.652926  1660.039603\n",
       " 80  2018-06-15  1825.362309  -1.197692  2013.004970  1652.595795\n",
       " 83  2018-06-18  1823.509189 -25.461632  2008.461415  1633.604282\n",
       " 86  2018-06-21  1824.576187  -2.635325  2028.740680  1625.857604\n",
       " 87  2018-06-22  1823.219820  -1.356367  2031.154610  1621.638257\n",
       " 90  2018-06-25  1829.000739 -23.908261  2044.062096  1617.129176\n",
       " 93  2018-06-28  1830.454916  -1.023253  2057.461555  1597.148590\n",
       " 97  2018-07-02  1843.873840 -25.535263  2095.893461  1594.188367\n",
       " 98  2018-07-03  1842.201564  -1.672277  2096.860324  1592.341050\n",
       " 99  2018-07-04  1840.113386  -2.088177  2094.583660  1576.071873\n",
       " 100 2018-07-05  1838.696547  -1.416839  2092.038198  1574.593761)"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "amazon.predict_future(days=100)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\Downloads\\Anaconda\\lib\\site-packages\\pystan\\misc.py:399: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
      "  elif np.issubdtype(np.asarray(v).dtype, float):\n"
     ]
    }
   ],
   "source": [
    "f = open('amzn11.txt','w')\n",
    "f.write(str(amazon.predict_future(days=100)))\n",
    "f.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
